/*
 * Copyright © 2024-2025 Wenze Wei
 *
 * This file is part of StadionOS.
 *
 * This Source Code Form is subject to the terms of the GNU General Public License, v. 2.0.
 * You can obtain a copy of the GPL at
 * https://www.gnu.org/licenses/old-licenses/gpl-2.0.html.
 *
 * Software distributed under the License is distributed on an "AS IS" basis,
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
 * the specific language governing rights and limitations under the License.
 */

#ifndef LIBS_LPI_H
#define LIBS_LPI_H

#include <yaml.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "./errorr.h"
#include "./fsd.h"
#include "./malloc.h"
#include "./math.h"
#include "./print.h"
#include "./process.h"
#include "./string.h"
#include "./time.h"

#define GLOBAL_BUFFER_SIZE 1024
#define CONFIG_USR "./usr.cof"
#define CONFIG_ENV "./env.cof"
#define USR Sgusr()

typedef enum {
    NODE_SCALAR,
    NODE_SEQUENCE,
    NODE_MAPPING
} TNodeType;

typedef enum {
    PATH_KEY,
    PATH_INDEX
} TPathPartType;

typedef struct TPathPart {
    TPathPartType type;
    union {
        char *key;
        size_t index;
    } value;
} TPathPart;

typedef struct TMapEntry TMapEntry;

typedef struct TNode {
    TNodeType type;
    union {
        char *scalar;
        struct {
            struct TNode **items;
            size_t count;
        } sequence;
        struct {
            TMapEntry *entries;
        } mapping;
    } data;
} TNode;

struct TMapEntry {
    char *key;
    TNode *value;
    TMapEntry *next;
};

ssize_t Srcof(const char *file, const char *key, void *buf,size_t bufsize);
int     Swcof(const char *file, const char *key, const char *value);
char*   Sgusr();
char*   Syaml(const char *file, const char *key);
char    Sgetenv(char *wh, char *key);

#endif //LIBS_LPI_H
